<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>智慧党建系统后台管理</title>
    <link rel="stylesheet" href="__PUBLIC__/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="__PUBLIC__/css/main.css" media="all"/>

    <link rel="stylesheet" href="__PUBLIC__/css/common.css">

    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="renderer" content="webkit"/>

    <link rel="stylesheet" href="__PUBLIC__/plugins/layui/layui_ext/dtree/dtree.css">
    <link rel="stylesheet" href="__PUBLIC__/plugins/layui/layui_ext/dtree/font/dtreefont.css">
    <link rel="stylesheet" href="__PUBLIC__/css/form.css">
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/plugins/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/plugins/ueditor/ueditor.all.min.js"></script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/plugins/ueditor/lang/zh-cn/zh-cn.js"></script>
    <style>
        .layui-form-select {
            z-index: 1000;
        }
    </style>
    {$style|raw|default=''}

    <!--[if lt IE 9]>
    <script src="__PUBLIC__/css/html5shiv.min.js"></script>
    <script src="__PUBLIC__/css/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript" src="__PUBLIC__/plugins/layui/layui.js"></script>
    <script type="text/javascript">
        "use strict";
    </script>
</head>
<body>

<!--主体-->
<div style="margin-bottom:0px;">
    <div class="admin-main layui-form layui-field-box">
        {if !empty($tips)}
        <blockquote class="layui-elem-quote layui-text">
            {volist name="tips" id="vo"}
            {$vo|raw}
            {/volist}
        </blockquote>
        {/if}

        {if $showBackBtn == true}
        <button class="layui-btn layui-btn-sm" id="backBtn" onclick="window.history.go(-1);">返回</button>
        <script>
            if (parent && parent.modelHelperList === true) {
                document.getElementById('backBtn').style.display = "none";
            }
        </script>
        {/if}

        {if !empty($title)}
        <fieldset class="layui-elem-field layui-field-title" id="title" style="margin-top: 20px;">
            <legend>{$title}</legend>
        </fieldset>
        <script>
            if (parent && parent.modelHelperList === true) {
                document.getElementById('title').style.display = "none";
            }
        </script>
        {/if}

        <form class="layui-form" action="" autocomplete="off">
            <script>
                let renderArr = [];
            </script>
            {volist name="fields" id="vo"}
            {switch vo.type}
            {case fieldset}
            <fieldset class="layui-elem-field layui-field-title in-layer-hide" style="margin-top: 20px;">
                <legend>{$vo.text}</legend>
            </fieldset>
            {/case}
            {case blockquote}
            <blockquote class="layui-elem-quote layui-text">
                {$vo.title|raw}
            </blockquote>
            {/case}
            {case text}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="{$vo.field}" placeholder="{$vo.placeholder|default=''}"
                           value="{$vo.value|default=''}" {$vo.attr|raw|default='' } class="layui-input"
                           {if !empty($vo.require)} lay-verify="required" {/if}
                    >
                </div>
                {if !empty($vo.tip)}
                <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                {/if}
            </div>
            {/case}
            {case number}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-inline">
                    <input type="number" name="{$vo.field}" placeholder="{$vo.placeholder|default=''}"
                           value="{$vo.value|default=''}" {$vo.attr|raw|default='' } class="layui-input"
                           {if !empty($vo.require)} lay-verify="number" {/if}
                    >
                </div>
                {if !empty($vo.tip)}
                <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                {/if}
            </div>
            {/case}
            {case password}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-inline">
                    <input type="password" autocomplete="new-password" name="{$vo.field}" {if $vo.verify!==false}
                           lay-verify="pass"
                           {/if} placeholder="{$vo.placeholder|default=''}"
                    value="{$vo.value|default=''}" {$vo.attr|raw|default=''} class="layui-input">
                </div>
                {if !empty($vo.tip)}
                <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                {/if}
            </div>
            {/case}
            {case email}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-inline">
                    <input type="email" name="{$vo.field}" lay-verify="email" placeholder="{$vo.placeholder|default=''}"
                           value="{$vo.value|default=''}" {$vo.attr|raw|default='' } class="layui-input">
                </div>
                {if !empty($vo.tip)}
                <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                {/if}
            </div>
            {/case}
            {case date}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="{$vo.field}" placeholder="{$vo.placeholder|default=''}" readonly
                           value="{$vo.value|default=''}" {$vo.attr|raw|default='' } class="layui-input"
                           id="LAY_date{$i}">
                </div>
                {if !empty($vo.tip)}
                <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                {/if}
            </div>
            <script>
                renderArr.push({type: 'date', id: '#LAY_date{$i}', range: '{$vo.range|default=false}'});
            </script>
            {/case}
            {case datetime}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-inline">
                    <input type="text" name="{$vo.field}" placeholder="{$vo.placeholder|default=''}" readonly
                           value="{$vo.value|default=''}" {$vo.attr|raw|default='' } class="layui-input"
                           id="LAY_date{$i}">
                </div>
                {if !empty($vo.tip)}
                <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                {/if}
            </div>
            <script>
                renderArr.push({type: 'datetime', id: '#LAY_date{$i}', range: '{$vo.range|default=false}'});
            </script>
            {/case}
            {case value="hidden"}
            <input type="hidden" name="{$vo.field}" value="{$vo.value|default=''}"/>
            {/case}
            {case select}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-inline">
                    <select name="{$vo.field}" {$vo.attr|raw|default=''} >
                        {volist name="vo.options" id="vv"}
                        <option value="{$key}" {$vv.disabled? 'disabled':''}
                        {if (isset($vo.value) && $vo.value==$key)} selected {/if}>{:isset($vv.title)?$vv.title:$vv}</option>
                        {/volist}
                    </select>
                </div>
                {if !empty($vo.tip)}
                <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                {/if}
            </div>
            {/case}
            {case radio}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-block">
                    {volist name="vo.options" id="vv"}
                    <input type="radio" name="{$vo.field}" value="{$key}" title="{$vv}" {if isset($vo.value) &&
                           $vo.value==$key} checked=""
                           {/if} >
                    {/volist}
                </div>
                {if !empty($vo.tip)}
                <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                {/if}
            </div>
            {/case}
            {case checkbox}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-block">
                    {volist name="vo.options" id="vv"}
                    <input type="checkbox" name="{$vo.field}[]" value="{$vv}" title="{$vv}"
                           {if in_array($key, json_decode($vo['value'], true))} checked="" {/if} >
                    {/volist}
                </div>
                {if !empty($vo.tip)}
                <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                {/if}
            </div>
            {/case}
            {case textarea}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-block">
                <textarea name="{$vo.field}" lay-verify="content" placeholder="{$vo.placeholder|default=''}"
                          {$vo.attr|raw|default='' }
                          class="layui-textarea" style="max-width: 380px;">{$vo.value|default=''}</textarea>
                    {if !empty($vo.tip)}
                    <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                    {/if}
                </div>
            </div>
            {/case}
            {case div}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-block">
                    <div {$vo.attr|raw|default=''} >
                        {$vo.value|default=''}
                    </div>
                    {if !empty($vo.tip)}
                    <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                    {/if}
                </div>
            </div>
            {/case}
            {case editor}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-block">
                <textarea class="layui-textarea layui-hide" name="{$vo.field}" lay-verify="content"
                          placeholder="{$vo.placeholder|default=''}"
                          id="LAY_editor{$i}">{$vo.value|default=''}</textarea>
                    {if !empty($vo.tip)}
                    <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                    {/if}
                </div>
            </div>
            <script>
                renderArr.push({type: 'editor', id: 'LAY_editor{$i}'});
            </script>
            {/case}
            {case ueditor}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-block">
                    <script id="LAY_ueditor{$i}" name="{$vo.field}" type="text/plain">{$vo.value|raw|default=''}
                    </script>
                    {if !empty($vo.tip)}
                    <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                    {/if}
                </div>
            </div>
            <script>
                renderArr.push({type: 'ueditor', id: 'LAY_ueditor{$i}'});
            </script>
            {/case}
            {case image}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-block">
                    <div class="layui-upload" style="display: flex;">
                        <input class="input" type="hidden" name="{$vo.field}" value="">
                        {if !empty($vo.value)}
                        <div class="img-item">
                            <a target="_blank" href="{$vo.value}">
                                <img class="img" lay-src="{$vo.value}">
                            </a>
                            <input class="input" type="hidden" name="{$vo.field}" value="{$vo.value}">
                            <span class="layui-icon layui-icon-close-fill remove-img-btn" data-max-num="1"
                                  title="移除图片"></span>
                        </div>
                        {/if}
                        <div class="add-file-btn" id="layui-btn{$i}" {if !empty($vo.value)}style="display:none;"{/if} >
                        <div class="layui-icon layui-icon-add-1"></div>
                        <div>添加图片</div>
                    </div>
                </div>
                {if !empty($vo.tip)}
                <div class="layui-form-mid layui-word-aux" style="padding-top: 0 !important;float:none;">{$vo.tip}</div>
                {/if}
                <script>
                    renderArr.push({
                        type: 'image',
                        field: '{$vo.field}',
                        btnId: '#layui-btn{$i}',
                        value: '["{$vo.value}"]',
                        maxNum: 1,
                    });
                </script>
            </div>
            {/case}
            {case images}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-block">
                    <div class="layui-upload" style="display: flex;flex-wrap: wrap;">
                        {volist name="vo.value" id="photo"}
                        <div class="img-item">
                            <a target="_blank" href="{$photo}">
                                <img class="img" lay-src="{$photo}">
                            </a>
                            <input class="input" type="hidden" name="{$vo.field}[]" value="{$photo}">
                            <span class="layui-icon layui-icon-close-fill remove-img-btn" data-max-num="-1"
                                  title="移除图片"></span>
                        </div>
                        {/volist}
                        <div class="add-file-btn" id="layui-btn{$i}">
                            <div class="layui-icon layui-icon-add-1"></div>
                            <div>添加图片</div>
                        </div>
                    </div>
                    {if !empty($vo.tip)}
                    <div class="layui-form-mid layui-word-aux" style="padding-top: 0 !important;float:none;">{$vo.tip}</div>
                    {/if}
                    <script>
                        renderArr.push({
                            type: 'images',
                            field: '{$vo.field}',
                            btnId: '#layui-btn{$i}',
                            value: '{:$vo.value?json_encode($vo.value):"[]"}',
                            maxNum: -1,
                        });
                    </script>
                </div>
            </div>
            {/case}
            {case file}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {if !empty($vo.require)}
                    <span class="require-text">{$vo.require}</span>
                    {/if}{$vo.title}
                </label>
                <div class="layui-input-block">
                    <div class="layui-input-inline">
                        <input type="text" name="{$vo.field}" placeholder="{$vo.placeholder|default=''}"
                               value="{$vo.value|default=''}" {$vo.attr|raw|default='' } class="layui-input"
                               id="input{$i}" readonly>
                    </div>
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-sm" id="layui-btn{$i}">上传文件</button>
                        <div class="layui-upload-list">
                            <p id="text{$i}"></p>
                        </div>
                        <a href="{$vo.value|default=''}" style="{if empty($vo.value)}display:none;{/if}"  id="open{$i}" target="_blank">查看</a>
                        <div class="layui-progress" style="display: none" lay-showPercent="yes"
                             lay-filter="progress{$i}" id="progress{$i}">
                            <div class="layui-progress-bar layui-bg-green" lay-percent="0%"></div>
                        </div>
                    </div>
                    {if !empty($vo.tip)}
                    <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                    {/if}
                </div>
            </div>
            <script>
                renderArr.push({
                    type: 'file',
                    btnId: '#layui-btn{$i}',
                    textId: '#text{$i}',
                    inputId: '#input{$i}',
                    openId: '#open{$i}',
                    aId: '#layui-upload-a{$i}',
                    progressId: '#progress{$i}',
                    progressLayFilter: 'progress{$i}',
                });
            </script>
            {/case}
            {case dtree}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    {$vo.title} </label>
                <div class="layui-input-inline" style="width: 520px;">
                    <ul id="{$vo.field}" class="dtree" data-id="0" data-value=""></ul>
                </div>
                {if !empty($vo.tip)}
                <div class="layui-form-mid layui-word-aux">{$vo.tip}</div>
                {/if}
            </div>
            <script>
                renderArr.push({
                    type: 'dtree',
                    ulId: '#{$vo.field}',
                    field: '{$vo.field}',
                });
            </script>
            {/case}
            {/switch}
            {/volist}
            {if $submit_btn_text}
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="*">立即提交</button>
                </div>
            </div>
            {/if}
        </form>
    </div>
</div>
<script>
    let showBackBtn = '{$showBackBtn}';
    console.log('parent.modelHelperList', parent.modelHelperList)
    layui.extend({
        inputTags: '/plugins/layui/inputTags/inputTags',
        yutons_sug: '/plugins/layui/yutons-mods/yutons_sug',
        dtree: '/plugins/layui/layui_ext/dtree/dtree',
    }).use(['form', 'layedit', 'laydate', 'jquery', 'upload', 'element', 'dtree', 'flow'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , jq = layui.jquery
            , element = layui.element
            , dtree = layui.dtree
            , flow = layui.flow
            , upload = layui.upload;

        if (parent && parent.modelHelperList === true) {
            jq('.in-layer-hide').hide();
        }

        flow.lazyimg();

        jq('body').click(function () {
            console.log('body click');
            jq("div[dtree-card").removeClass("dtree-select-show layui-anim layui-anim-upbit");
        });

        //移除图片
        jq('body').on('click', '.remove-img-btn', function () {
            let max = jq(this).data('max-num');
            let btn = jq(this).closest('.layui-upload').find('.add-file-btn');
            jq(this).closest('.img-item').remove();
            maxImg(btn, max);
            return false;
        });

        //最多不能超过3张图片
        function maxImg(element, maxNum) {
            let upDiv = jq(element).closest('.layui-upload');
            let length = upDiv.find('.img-item').length;
            if (maxNum > -1 && length >= maxNum) {
                upDiv.find('.add-file-btn').hide()
            } else {
                upDiv.find('.add-file-btn').show()
            }
        }

        //创建编辑器
        let uploadInst = [];
        renderArr.forEach(function (v, i) {
            if (v.type == 'editor') {
                //编辑器
                renderArr[i].editIndex = layedit.build(v.id, {
                    uploadImage: {
                        url: '{:url("Upload/layedit_upimage")}',
                        type: 'post'
                    }
                });
            } else if (v.type == 'ueditor') {
                //编辑器
                var ue = UE.getEditor(v.id, {
                    initialFrameHeight: 400,
                });
            } else if (v.type == 'date') {
                console.log(v)
                //日期
                laydate.render({
                    elem: v.id
                    , range: v.range
                    , trigger: 'click'
                });
            } else if (v.type == 'datetime') {
                console.log(v)
                //日期
                laydate.render({
                    elem: v.id
                    , type: 'datetime'
                    , range: v.range
                    , trigger: 'click'
                });
            } else if (v.type == 'image' || v.type === 'images') {
                //多图片上传
                var imgIndex = JSON.parse(v.value).length;
                console.log('imgIndex', imgIndex)
                uploadInst[i] = upload.render({
                    elem: v.btnId
                    , url: '{:url("Upload/upimage")}'
                    , progress: function (n) {
                        console.log('progress', v.field + imgIndex)
                        var percent = n + '%' //获取进度百分比
                        element.progress("progress" + v.field + imgIndex, percent);
                    }
                    , before: function (obj) {
                        imgIndex++;
                        console.log('before', imgIndex)
                        form.render();
                        //预读本地文件示例，不支持ie8
                        let name = v.type == 'image' ? v.field : v.field + "[]";
                        obj.preview(function (index, file, result) {
                            jq(v.btnId).before(`<div class="img-item" id="img-item${v.field + imgIndex}">
                                <a class="img-a" target="_blank" href="${result}">
                                    <img class="img" style="" src="${result}">
                                </a>
                                <input class="input" type="hidden" name="${name}">
                                <span class="layui-icon layui-icon-close-fill remove-img-btn" title="移除图片"></span>
                                <div class="progress-bg">
                                    <div class="layui-progress" lay-showpercent="yes" lay-filter="progress${v.field + imgIndex}">
                                        <div class="layui-progress-bar layui-bg-green" lay-percent="0%" style="width: 0%;">
                                            <span class="layui-progress-text">0%</span>
                                        </div>
                                    </div>
                                </div>
                            </div>`);
                            maxImg(jq(v.btnId), v.maxNum)
                        });
                    }
                    , done: function (res) {
                        console.log('done', "img-item" + v.field + imgIndex)
                        //如果上传失败
                        let imgItem = jq("#img-item" + v.field + imgIndex);
                        if (res.code !== 200) {
                            imgItem.remove();
                            maxImg(jq(v.btnId), v.maxNum)
                            return layer.msg(res.msg);
                        }
                        //上传成功
                        imgItem.find(".progress-bg").hide();
                        imgItem.find('.input').val(res.path);
                        imgItem.find('.img').attr('src', res.path);
                        imgItem.find('.img-a').attr('href', res.path);
                    }
                    , error: function () {
                        //演示失败状态，并实现重传
                        let imgItem = jq("#img-item" + v.field + imgIndex);
                        imgItem.remove();
                        maxImg(jq(v.btnId), v.maxNum)
                        return layer.msg('上传失败，请重试');
                    }
                });
            } else if (v.type == 'excel') {
                //excel上传
                uploadInst[i] = upload.render({
                    elem: v.btnId
                    , url: '{:url("Upload/upExcel")}'
                    , accept: 'file'
                    , exts: 'xls|xlsx'
                    , progress: function (n) {
                        var percent = n + '%' //获取进度百分比
                        element.progress(v.progressLayFilter, percent);
                    }
                    , before: function (obj) {
                        jq(v.progressId).show();
                        element.progress(v.progressLayFilter, 0);
                    }
                    , done: function (res) {
                        //如果上传失败
                        if (res.code != 200) {
                            jq(v.progressId).hide();
                            element.progress(v.progressLayFilter, 0);
                            return layer.msg(res.msg);
                        }
                        //上传成功
                        jq(v.inputId).val(res.path)
                    }
                    , error: function () {
                        //演示失败状态，并实现重传
                        var demoText = jq(v.textId);
                        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-sm layui-btn-xs demo-reload">重试</a>');
                    }
                });
            } else if (v.type == 'file') {
                //excel上传
                uploadInst[i] = upload.render({
                    elem: v.btnId
                    , url: '{:url("Upload/upfile")}'
                    , accept: 'file'
                    // , exts: '.'
                    , progress: function (n) {
                        var percent = n + '%' //获取进度百分比
                        element.progress(v.progressLayFilter, percent);
                    }
                    , before: function (obj) {
                        jq(v.progressId).show();
                        element.progress(v.progressLayFilter, 0);
                    }
                    , done: function (res) {
                        //如果上传失败
                        if (res.code != 200) {
                            return layer.msg(res.msg);
                        }
                        //上传成功
                        jq(v.inputId).val(res.path);
                        jq(v.openId).attr('href', res.path).show()
                    }
                    , error: function () {
                        //演示失败状态，并实现重传
                        var demoText = jq(v.textId);
                        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-sm layui-btn-xs demo-reload">重试</a>');
                    }
                });
            } else if (v.type == 'dtree') {
                //下拉树
                let dataUrl = "{:url('depDtree')}";//TODO 这里以后做活的
                console.log('dataUrl: ', dataUrl);
                let DepTree = dtree.renderSelect({
                    elem: v.ulId,
                    width: "480",
                    selectCardHeight: "200",
                    line: true,  // 显示树线
                    // icon: "-1",  // 隐藏二级图标
                    url: dataUrl,
                    request: {"itemId": "{$id|default=''}", "field": v.field},  // 将你需要传入的固定值放入该属性中，组件就会在发起请求时将该值带入
                    type: "all",
                    dot: false,
                    checkbar: true,
                    checkbarType: "self",
                    // checkbarType: "no-all",
                    // checkbarData: 'all',
                    initLevel: 5,
                    response: {
                        parentId: 'parent_id'
                    },
                    // select: true, //指定下拉树模式
                    done: function () {
                        DepTree.selectCheckboxVal()
                    }
                });
            }
        });
        console.log('renderArr', renderArr)
        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , content: function (value) {
                renderArr.forEach(function (v, i) {
                    if (v.type == 'editor') {
                        layedit.sync(i);
                    }
                });
                //layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(*)', function (data) {
            console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
            console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            let loading = layer.load(2, {
                shade: [0.2, '#000']
            });
            let url = self.location.href;
            jq.post(url, data.field, function (res) {
                console.log(res);
                layer.close(loading);
                let time = typeof res.wait == 'number' ? res.wait * 1000 : 3000;
                if (res.code != 1) {
                    if (time > 0) {
                        return layer.msg(res.msg, {time: time});
                    } else {
                        var index = layer.confirm(res.msg, {
                            btn: ['确定'] //按钮
                        }, function () {
                            layer.close(index);
                        });
                        return;
                    }
                } else {
                    if (time > 0) {
                        layer.msg(res.msg, {
                                time: time - 2000 > 0 ? time - 2000 : time
                            }, function () {
                                if (showBackBtn === '1') {
                                    if (parent && parent.modelHelperList === true) {
                                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                        parent.layer.close(index);
                                        parent.layui.table && typeof parent.layui.table.reload == 'function' && parent.layui.table.reload('testReload');
                                        typeof parent.frameSubmitCloseCallback == 'function' && parent.frameSubmitCloseCallback();
                                    } else {
                                        history.back();
                                    }
                                } else {
                                    window.location.reload();
                                }
                            }
                        );
                    } else {
                        var index = layer.confirm(res.msg, {
                            btn: ['确定'] //按钮
                        }, function () {
                            layer.close(index);
                            if (showBackBtn === '1') {
                                if (parent && parent.modelHelperList === true) {
                                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                    parent.layer.close(index);
                                    parent.layui.table && typeof parent.layui.table.reload == 'function' && parent.layui.table.reload('testReload');
                                    typeof parent.frameSubmitCloseCallback == 'function' && parent.frameSubmitCloseCallback();
                                } else {
                                    history.back();
                                }
                            } else {
                                window.location.reload();
                            }
                        });
                        return;
                    }
                }
            }).error(function () {
                layer.close(loading);
                layer.msg('服务器错误！');
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //表单初始赋值
        form.val('example', {
            "username": "贤心" // "name": "value"
            , "password": "123456"
            , "interest": 1
            , "like[write]": true //复选框选中状态
            , "close": true //开关状态
            , "sex": "女"
            , "desc": "我爱 layui"
        });

        //多图片上传
        upload.render({
            elem: '#test2'
            , url: '/upload/'
            , multiple: true
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo2').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img">')
                });
            }
            , done: function (res) {
                //上传完毕
            }
        });
    });
</script>
</body>
</html>